package pacman;

import gui.GhostPanel;
import gui.GuiTest;
import gui.MainGui;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import pacman.protocol.CommandParser;

import maze.Barcode;
import maze.Coordinate;
import maze.Location;
import maze.Maze;
import robots.Ghost;
import robots.OwnGhost;
import robots.Pacman;
import robots.RealGhost;
import robots.VirtualGhost;
import robots.analyser.BarcodeAnalyser;
import robots.analyser.SectorAnalyserV1;
import robots.analyser.SectorAnalyserV2;
import robots.behaviour.Explorer;
import robots.behaviour.MazeCorrector;
import sensors.realSensors.RealInfraredSensor;
import sensors.realSensors.RealLightSensor;
import sensors.realSensors.RealUltrasonicSensor;
import sensors.virtualSensors.VirtualLightSensor;
import simulation.ColorMap;
import simulation.Simulator;
import bluetoothCommunication.Communicator;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.ShutdownSignalException;

public class Main {
	
	
	public static void main (String [] args) throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException{
//		DemoReal();
		//testMaze();
		//testGui();
		//testCommunicator(); FAILS
		
//		testColorMap();
		//testBarcodeAnalyser();
		//testRidingBarcodeAnalyser();
		//runVirtual();
		//testExplorer();
	//	testBarcodesVirtual();

//		testExplorerDistributed();
//testExplorer();
//		testExplorerOneGhostVirtualSensorInnaccurate();
		//testRealRobot();
//		testRealRobotDistributed();
//		testExplorer();
		//testExplorerOneGhostVirtualSensorInnaccurate();
//		testExplorerOneGhost();
//		testExplorerVirtualSensorsInaccurate();
//		testRealRobot();
//		testRealDistributed();
//		testHybrid();
		//testRealRobotMazeExplorer();
//		testCrash();
//		testSectorAnalyserV2();
		//testSectorAnalyserV1();
		//testRabbit();
		//realandSimulation(args);
		//testGhost();
//		testRobotMovement();
//		testOneOfFour();
//		testAngleCorrection();
//		testMazeCorrector();\
//		testFourSimulators();
//		testfoursimulatorshybrid();
		demo3Individueel();
//		testPing();
//		robotGO(3,0,"../wolfraam.txt");
		
	}
	
	//WERKT NIET - ignore pl0x
	private static void robotGO(int numberOfVirtualGhosts, int numberOfRealGhosts, String mazeLocation) throws IOException, InterruptedException{
		if(numberOfRealGhosts+numberOfVirtualGhosts > 4) throw new IllegalArgumentException("Niet meer dan 4 ghosts mogelijk!");
		if(numberOfRealGhosts > 1) throw new IllegalArgumentException("Niet meer dan 1 echte ghost mogelijk!");
		
		int numberOfGhosts = numberOfRealGhosts + numberOfVirtualGhosts;
		
		File mazeFile = new File(mazeLocation);
		
		Game tempGame = new Game(numberOfGhosts);
		
		CommandParser tempParser = new CommandParser(tempGame);
		GameInformation info = tempParser.parseFile(mazeFile);
		Coordinate [] playerCoordinates = info.playerCoordinates;
		Maze maze = info.maze;
		Pacman pacman = new Pacman();
		pacman.setCoordinate(info.pacmanCoordinate);
		
		String [] ghostNames = {"Jos", "Jef", "Jan", "Jeroen"};
		
		Game [] games = new Game[numberOfGhosts];
		Simulator [] simulators = new Simulator[numberOfGhosts];
		OwnGhost [] ghosts = new OwnGhost[numberOfGhosts];
		Thread ghostThreads[] = new Thread[numberOfGhosts];
		
		for(int i = 0; i < numberOfVirtualGhosts; i++){
			games[i] = new Game(numberOfGhosts);
			CommandParser parser = new CommandParser(games[i]);
			ColorMap colorMap = new ColorMap();
			colorMap.setupMap(maze, maze.getSize(),maze.getSize());
			simulators[i] = new Simulator(maze, colorMap);
			simulators[i].setPacman(pacman);
			simulators[i].setMaze(maze);
			ghosts[i] = new VirtualGhost(games[i], ghostNames[i], simulators[i]);
			games[i].addOwnGhost(ghosts[i]);
			simulators[i].addGhost(ghosts[i], Coordinate.toLocation(playerCoordinates[i]), 0);
		}	
		
		if(numberOfRealGhosts == 1){
			games[numberOfVirtualGhosts] = new Game(numberOfGhosts);
			ColorMap colorMap = new ColorMap();
			colorMap.setupMap(maze, maze.getSize(),maze.getSize());
			simulators[numberOfVirtualGhosts] = new Simulator(maze, colorMap);
			simulators[numberOfVirtualGhosts].setPacman(pacman);
			simulators[numberOfVirtualGhosts].setMaze(maze);
			ghosts[numberOfVirtualGhosts] = new RealGhost(games[numberOfVirtualGhosts], ghostNames[numberOfVirtualGhosts], simulators[numberOfVirtualGhosts], new Communicator());
			games[numberOfVirtualGhosts].addOwnGhost(ghosts[numberOfVirtualGhosts]);
			simulators[numberOfVirtualGhosts].addGhost(ghosts[numberOfVirtualGhosts], Coordinate.toLocation(playerCoordinates[numberOfVirtualGhosts]), 0);
		}
		
		for(int i = 0; i < numberOfGhosts; i++){
			ghostThreads[i] = new Thread(new GhostRunner(ghosts[i]));
			ghostThreads[i].start();
			Thread.sleep(500);
		}
		
		MainGui gui = new MainGui(games[0], maze, simulators[0]);
	}
	
	private static void demo3Individueel() throws IOException {
		File file = new File("../wolfraam3.txt");
		
		int gekozenPositie = 0;
		
		Coordinate [] playerCoordinates = CommandParser.givePlayersPositions(file,gekozenPositie);
		Maze maze = CommandParser.getMaze(file);
		CommandParser.addBarcodes(file, maze);
		Pacman pacman = new Pacman();
		pacman.setCoordinate(CommandParser.givePacmanPosition(file));
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());

		OwnGhost virt01 = runOneGhost(true, "virt01", maze, colorMap, pacman, Coordinate.toLocation(playerCoordinates[0]), 0);
		runOneGhost(true, "Virt02", maze, colorMap,  pacman, Coordinate.toLocation(playerCoordinates[1]), 90);
		runOneGhost(true, "Virt03", maze, colorMap,  pacman, Coordinate.toLocation(playerCoordinates[2]), 180);
//		runOneGhost(false, "jos", maze, colorMap,  pacman, Coordinate.toLocation(playerCoordinates[3]), 0);
		runOneGhost(true, "Jos", maze, colorMap,  pacman, Coordinate.toLocation(playerCoordinates[3]), -90);
	}
	private static OwnGhost runOneGhostDemo(boolean virtual, String name, Maze m, ColorMap c, Location pLoc, Location gLoc, int gRot) throws IOException
	{
		File file = new File("../wolfraam.txt");

		Simulator sim = new Simulator(m, c);
		Pacman p = new Pacman();
		sim.setPacman(p);
		sim.setPacmanLocation(pLoc);
		OwnGhost g = null;
		Game game = new Game();
		if(virtual)
		{
			g = new VirtualGhost(game, name,sim, true);
		}
		else
		{
			g = new RealGhost(game, name, sim, new Communicator());
			((SectorAnalyserV1)(g.sectorAnalyser)).frontCompensation=3;
			g.xOffsetSensor=3;
			g.yOffsetSensor=0;
		}
		
		game.addOwnGhost(g);
		sim.addGhost(g, gLoc, gRot);
		
		Thread ghostThread = new Thread(new GhostRunner(g));
		ghostThread.start();
		
		MainGui gui = new MainGui(game, m, sim);
		
		sleep(500);
		return g;
	}

	private static void testPing() throws NumberFormatException, IOException, InterruptedException {
		File file = new File("../wolfraam2.txt");
		
		int numberOfPlayers = 3;
		
		
		Pacman pacman = new Pacman();
		
		Game []games = new Game[numberOfPlayers];
		
		Simulator[] simulators = new Simulator[numberOfPlayers];
		
		Location[] robotLocations = {new Location(20,220),
									new Location(20,20),
									new Location(300,20),
									new Location(300, 220)};
		
		VirtualGhost [] ghosts = new VirtualGhost[numberOfPlayers];
		String [] ghostNames = {"ghost1", "ghost2", "ghost3", "ghost4"};
		
		Maze parsedMaze = null;
		Thread [] ghostThreads = new Thread[numberOfPlayers];
		for(int i = 0; i < numberOfPlayers; i++){
			games[i] = new Game();
			games[i].NUMBEROFGHOSTS=3;
			CommandParser parser = new CommandParser(games[i]);
			parsedMaze = parser.parseFile(file);
			ColorMap colorMap = new ColorMap();
			colorMap.setupMap(parsedMaze, parsedMaze.getSize(),parsedMaze.getSize());
			simulators[i] = new Simulator(parsedMaze, colorMap);
			pacman.setCoordinate(games[i].getPacman().getCoordinate());
			simulators[i].setPacman(pacman);
			simulators[i].setMaze(parsedMaze);
			ghosts[i] = new VirtualGhost(games[i], ghostNames[i], simulators[i]);
			games[i].addOwnGhost(ghosts[i]);
			simulators[i].addGhost(ghosts[i], robotLocations[i], 0);
			
			ghostThreads[i] = new Thread(new GhostRunner(ghosts[i]));
			ghostThreads[i].start();
			Thread.sleep(500);
		}	
		
		Thread.sleep(1500);
		ghosts[0].protocolSender.sendPING("*", ":LSJKf:j");
		MainGui gui = new MainGui(games[0], parsedMaze, simulators[0]);
		
	}

	private static OwnGhost runOneGhost(boolean virtual, String name, Maze maze, ColorMap colorMap,Pacman pacman, Location ghostLoc, int gRot) throws IOException
	{
		Simulator sim = new Simulator(maze, colorMap);
		Game game = new Game();
		sim.setPacman(pacman); //Location wordt dan al gezet
		OwnGhost g = null;
		
		if(virtual)
		{
			g = new VirtualGhost(game, name,sim, true);
		}
		else
		{
			g = new RealGhost(game, name, sim, new Communicator());
			((SectorAnalyserV1)(g.sectorAnalyser)).frontCompensation=3;
			g.xOffsetSensor=3;
			g.yOffsetSensor=0;
		}
		
		game.addOwnGhost(g);
		sim.addGhost(g, ghostLoc, gRot);
		
		Thread ghostThread = new Thread(new GhostRunner(g));
		ghostThread.start();
		sleep(100);
		MainGui gui = new MainGui(game, maze, sim);

		return g;
	}
	
	private static void testfoursimulatorshybrid() throws IOException {
		char[][] walls = {
				{0,1,0,1,0,1,0,1,0},
				{1,2,1,2,2,1,2,2,1},
				{1,2,2,2,2,1,2,2,1},
				{1,2,1,2,2,2,1,2,1},
				{1,1,1,1,2,1,2,1,1}};

		char[][]bigMaze = {
				{0,1,0,1,0,1,0,1,0,1,0,1,0},
				{1,1,2,1,2,2,1,1,2,2,2,2,1},
				{1,2,2,1,2,2,2,1,2,2,1,2,1},
				{1,1,2,1,1,2,1,2,1,2,1,1,1},
				{1,1,2,1,2,2,2,2,2,2,1,2,1},
				{1,2,1,1,2,2,1,1,1,2,2,1,1},
				{1,2,2,1,2,1,2,2,2,1,1,1,1},
				{1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,1,2,1,1,1,2,1,1,1,1,1,1}};
//		Bij gebruik van een FILE uncommenten
// 		Niet vergeten andere maze en pacman te uncommenten
//		CommandParser tempParser = new CommandParser(tempGame);
//		GameInformation info = tempParser.parseFile(mazeFile);
//		Coordinate [] playerCoordinates = info.playerCoordinates;
//		
//		Maze maze = info.maze; //Barcodes zijn al toegevoegd 
//		
//		
//		Pacman pacman = new Pacman();
//		pacman.setCoordinate(info.pacmanCoordinate);
		
		
		Maze maze = new Maze(bigMaze);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize()); //Barcodes worden in setUP al goed gezet
		Simulator simulator = new Simulator(maze, colorMap);
		
		//colorMap.AddBarcode(0, 1, "00111110", 1);
		//colorMap.AddBarcode(3, 1, "00011110", 1);
		//colorMap.AddBarcode(2, 3, "00101010", 0);
		
		//BIGMAZE
		colorMap.AddBarcode(2, 1, "01001100", 0);
		colorMap.AddBarcode(4, 1, "00010000", 0);
		colorMap.AddBarcode(4, 5, "01100010", 1);
		colorMap.AddBarcode(1, 6, "00101100", 0);
		
		//simulator.getMaze().addBarcode(new Coordinate(0, 1), "00111110", 1);
		//simulator.getMaze().addBarcode(new Coordinate(3, 1), "00011110", 1);
		//simulator.getMaze().addBarcode(new Coordinate(2, 3), "00101010", 0);
		
		//BIGMAZE
		simulator.getMaze().addBarcode(new Coordinate(2, 1), "01001100", 0);
		simulator.getMaze().addBarcode(new Coordinate(4, 1), "00010000", 0);
		simulator.getMaze().addBarcode(new Coordinate(4, 5), "01100010", 1);
		simulator.getMaze().addBarcode(new Coordinate(1, 6), "00101100", 0);
		
		//Uncommenten als je een FILE gebruikt!
		Coordinate [] playerCoordinates = { new Coordinate(0,0), new Coordinate(5,7), new Coordinate(0, 7), new Coordinate(5, 1)}; 
		
		OwnGhost virt01 = runOneGhost(true, "virt01", maze, colorMap, new Location(100, 100), Coordinate.toLocation(playerCoordinates[0]), 0);
		runOneGhost(true, "Virt02", maze, colorMap, new Location(100, 100), Coordinate.toLocation(playerCoordinates[1]), 0);
		runOneGhost(true, "Virt03", maze, colorMap, new Location(100, 100), Coordinate.toLocation(playerCoordinates[2]), 0);
//		runOneGhost(false, "jos", maze, colorMap, new Location(100, 100), Coordinate.toLocation(playerCoordinates[3]), 0);
		runOneGhost(true, "Jos", maze, colorMap, new Location(100, 100), Coordinate.toLocation(playerCoordinates[3]), -90); 
	

		
	}
	private static void testRealDistributed() throws IOException {
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,4));

		simulator.setPacman(pacman);
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);
		
	    Game game = new Game();
	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());

		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.xOffsetSensor=3;
		ghost.yOffsetSensor=0;


		game.addOwnGhost(ghost);
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
//		GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		
		t1.start();
		
//		GhostPanel panel1 = new GhostPanel(ghost, game,ImageIO.read(new File("../PenOTiles/robot.png"))) ;
		MainGui mainGui = new MainGui(game, maze, simulator);
		
	}
	private static void testHybrid() throws IOException {
		/*
		4x4
         _?_?_?_?
		| |  _  |
		|    _  |
		| |   | |
		|_|_ _ _|
		 */
		
		char[][] walls = {
				{0,1,0,1,0,1,0,1,0},
				{1,2,1,2,2,1,2,2,1},
				{1,2,2,2,2,1,2,2,1},
				{1,2,1,2,2,2,1,2,1},
				{1,1,1,1,2,1,2,1,1}};

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(3,3));

		simulator.setPacman(pacman);
		colorMap.AddBarcode(0, 1, "00111110", 1);
		colorMap.AddBarcode(3, 1, "00011110", 1);
		colorMap.AddBarcode(2, 3, "00101010", 0);
		
		simulator.getMaze().addBarcode(new Coordinate(0, 1), "00111110", 1);
		simulator.getMaze().addBarcode(new Coordinate(3, 1), "00011110", 1);
		simulator.getMaze().addBarcode(new Coordinate(2, 3), "00101010", 0);
		
		
		
	    Game game = new Game();
	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());
	    VirtualGhost ghost1 = new VirtualGhost(game,"Jef", simulator,true);
		VirtualGhost ghost2 = new VirtualGhost(game,"Jan", simulator,true);
		VirtualGhost ghost3 = new VirtualGhost(game,"Joost", simulator,true);
		ghost1.setSpeed(360);
		ghost2.setSpeed(360);
		ghost3.setSpeed(360);

		
		OwnGhost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.addFourOwnGhost(ghosts);
		
		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.xOffsetSensor=3;
		ghost.yOffsetSensor=0;



		game.ownGame=true;
		
		simulator.addGhost(ghost, new Location(20, 20), -90);
		simulator.addGhost(ghost1, new Location(140, 20), 0);
		simulator.addGhost(ghost2, new Location(20, 140), 0);
		simulator.addGhost(ghost3, new Location(140, 140), 0);
		
		
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
//		GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3 = new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));

		
		t1.start();
		t2.start();
		t3.start();
		t4.start();

		
//		GhostPanel panel1 = new GhostPanel(ghost, game,ImageIO.read(new File("../PenOTiles/robot.png"))) ;
		MainGui mainGui = new MainGui(game, maze, simulator);

	}
	private static void testSectorAnalyserV1() throws IOException {
		char[][] walls =  //index with maze[-y][x]
				{{0,1,0,1,0,1,0,1,0},
					{1,2,2,1,2,1,2,2,1},
					{1,1,1,1,2,1,2,2,1},
					{1,2,2,1,2,1,2,2,1},
					{1,1,2,1,2,1,1,1,1}};
				
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
//		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(1000,1000));
//		simulator.setPacman(pacman);
//		colorMap.AddBarcode(1, 3, "01000110", 0);
//		colorMap.AddBarcode(5, 2, "01110110", 0);
//		colorMap.AddBarcode(0, 2, "01011100", 1);
//		
//		simulator.getMaze().addBarcode(1, 3, "01000110", 0);
//		simulator.getMaze().addBarcode(5, 2, "01110110", 0);
//		simulator.getMaze().addBarcode(0, 2, "01011100", 1);
		Game game = new Game();
		Channel channel = game.getChannel();
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos",null);
		Communicator communicator = new Communicator();		
		ghost.setCommunicator(communicator);
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost.xOffsetSensor=-4;
		ghost.yOffsetSensor=3;
		SectorAnalyserV1 sectorAnalyser =  new SectorAnalyserV1();
//		sectorAnalyser.readingsPerQuadrant = 5;
//		sectorAnalyser.angleMargin = 20;
		ghost.sectorAnalyser = sectorAnalyser;
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		simulator.speed = 800;
		
		GuiTest Gui = new GuiTest(simulator);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();
	}
	private static void testRealRobot() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,4));

		simulator.setPacman(pacman);
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);
		
	    Game game = new Game();
	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());

		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.xOffsetSensor=3;
		ghost.yOffsetSensor=0;


		game.addOwnGhost(ghost);
		game.ownGame=true;
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
//		GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		
		t1.start();
		
//		GhostPanel panel1 = new GhostPanel(ghost, game,ImageIO.read(new File("../PenOTiles/robot.png"))) ;
		MainGui mainGui = new MainGui(game, maze, simulator);

		
	}
	private static void testSectorAnalyserV2() throws IOException {
		char[][] walls =  //index with maze[-y][x]
				{{0,1,0,1,0,1,0,1,0},
					{1,2,2,1,2,1,2,2,1},
					{1,1,1,1,2,1,2,2,1},
					{1,2,2,1,2,1,2,2,1},
					{1,1,2,1,2,1,1,1,1}};
				
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
//		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(1000,1000));
//		simulator.setPacman(pacman);
//		colorMap.AddBarcode(1, 3, "01000110", 0);
//		colorMap.AddBarcode(5, 2, "01110110", 0);
//		colorMap.AddBarcode(0, 2, "01011100", 1);
//		
//		simulator.getMaze().addBarcode(1, 3, "01000110", 0);
//		simulator.getMaze().addBarcode(5, 2, "01110110", 0);
//		simulator.getMaze().addBarcode(0, 2, "01011100", 1);
		
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos");
		Communicator communicator = new Communicator();		
		ghost.setCommunicator(communicator);
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost.xOffsetSensor=-4;
		ghost.yOffsetSensor=1;
		ghost.frontCompensation=4;
		SectorAnalyserV2 sectorAnalyser =  new SectorAnalyserV2();
		sectorAnalyser.readingsPerQuadrant = 5;
		sectorAnalyser.angleMargin = 20;
		ghost.sectorAnalyser = sectorAnalyser;
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		simulator.speed = 800;
		
		GuiTest Gui = new GuiTest(simulator, null);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();
	}

	private static void testCrash() throws IOException {
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
		pacman.setLocation(new Location(1000,1000));
		simulator.setPacman(pacman);
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(1, 3, "01000110", 0);
		simulator.getMaze().addBarcode(5, 2, "01110110", 0);
		simulator.getMaze().addBarcode(0, 2, "01011100", 1);
		
	    Game game = new Game();
		Channel channel = game.getChannel();
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos");
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost.sectorAnalyser = new SectorAnalyserV2();
		Ghost[] ghosts = {ghost};
		
		game.setGhosts(ghosts);
		
		simulator.addGhost(ghost, new Location(140, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.speed = 800;
		GuiTest Gui = new GuiTest(simulator, game);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();
		
		
	}

	private static void testAngleCorrection() throws IOException {
		Game game = new Game();
		Maze maze = game.getParser().parseFile(new File("../PenOTiles/wolfraam.txt"));
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Ghost[] ghosts = game.getGhosts();
		Ghost ghost = ghosts[0];
		ghost.xOffsetSensor=-4;
		ghost.yOffsetSensor=3;
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		Communicator communicator = new Communicator();		
		ghost.setCommunicator(communicator);
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		int[][] positions = game.getPositions();
		simulator.addGhost(ghost, new Location(positions[0][0], positions[0][1]), 0);
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);


	}

	private static void Demo() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		Game game = new Game();
		Maze maze = game.getParser().parseFile(new File("/home/s0219269/workspace/P&O/src/pacman/wolfraam.txt"));
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = game.getPacman();
		simulator.setPacman(pacman);
		for(Barcode b : maze.getBarcodes()) colorMap.AddBarcode(b.getX(), b.getY(), b.getCode(), b.getDirection());
		Ghost[] ghosts = game.getGhosts();
		Ghost ghost = ghosts[0];//new Ghost(new Location(20,20), 0, "Jos");
		Ghost ghost1 = ghosts[1];//new Ghost(new Location(20,20), 0, "Jef");
		Ghost ghost2 = ghosts[2];//new Ghost(new Location(20,20), 0, "Jan");
		Ghost ghost3 = ghosts[3];//new Ghost(new Location(20,20), 0, "Jeroen");
		//Ghost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		//game.setGhosts(ghosts);
		/*ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(Config.HOST_NAME);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(Config.EXCHANGE_NAME, "fanout");*/
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost1.setStrategy( new Explorer(ghost1.getMaze()));
		ghost2.setStrategy(new Explorer(ghost2.getMaze()));
		ghost3.setStrategy(new Explorer(ghost3.getMaze()));
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		int[][] positions = game.getGhostPositions();
		simulator.addGhost(ghost, new Location(positions[0][0], positions[0][1]), 0);
		simulator.addGhost(ghost1, new Location(positions[1][0], positions[1][1]), 0);
		simulator.addGhost(ghost2, new Location(positions[2][0], positions[2][1]), 0);
		simulator.addGhost(ghost3, new Location(positions[3][0], positions[3][1]), 0);
		simulator.speed = 600;
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
		t2.start();
		t3.start();
		t4.start();
	}
	private static void testRobotMovement() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		Game game = new Game();
		Maze maze = game.getParser().parseFile(new File("../PenOTiles/wolfraam.txt"));
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Ghost[] ghosts = game.getGhosts();
		Ghost ghost = ghosts[0];
		ghost.setStrategy (new Explorer(ghost.getMaze()));
		ghost.xOffsetSensor=-4;
		ghost.yOffsetSensor=3;
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setLightSensor(new VirtualLightSensor(ghost));
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		Communicator communicator = new Communicator();		
		ghost.setCommunicator(communicator);
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		int[][] positions = game.getGhostPositions();
		simulator.addGhost(ghost, new Location(positions[0][0], positions[0][1]), 0);
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();

	}
	private static void DemoReal() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		Game game = new Game();
		Maze maze = game.getParser().parseFile(new File("../PenOTiles/wolfraam.txt"));
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = game.getPacman();
		simulator.setPacman(pacman);
		for(Barcode b : maze.getBarcodes()) colorMap.AddBarcode(b.getX(), b.getY(), b.getCode(), b.getDirection());
//		Ghost[] ghosts = game.getGhosts();
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos");
		Ghost ghost1 =new Ghost(new Location(20,20), 0, "Jef");
		Ghost ghost2 = new Ghost(new Location(20,20), 0, "Jan");
		Ghost ghost3 = new Ghost(new Location(20,20), 0, "Jeroen");
		//Ghost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		//game.setGhosts(ghosts);
		/*ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(Config.HOST_NAME);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(Config.EXCHANGE_NAME, "fanout");*/
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost1.setStrategy(new Explorer(ghost1.getMaze()));
		ghost2.setStrategy(new Explorer(ghost2.getMaze()));
		ghost3.setStrategy(new Explorer(ghost3.getMaze()));
//		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
//		ghost.setLightSensor(new RealLightSensor(ghost));
//		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
//		Communicator communicator = new Communicator();		
//		ghost.setCommunicator(communicator);
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		Location[] positions = game.robotLocations;
		simulator.addGhost(ghost, positions[0], 0);
		simulator.addGhost(ghost1, positions[1], 0);
		simulator.addGhost(ghost2, positions[2], 0);
		simulator.addGhost(ghost3, positions[3], 0);
		simulator.speed = 600;
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
		t2.start();
		t3.start();
		t4.start();
	}
	
	
	private static void testRealRobotMazeExplorer() throws IOException {
		/*
		4x6

		?????_ _
		????| | |
		?_?_|   |
		|  _ _| |
		|    _| |
		| | |????
		|_ _|????
		 */
		
		char[][] walls = {
				{0,0,0,0,0,1,0,1,0},
				{0,0,0,0,1,2,1,2,1},
				{0,1,0,1,1,2,2,2,1},
				{1,2,2,1,2,1,1,2,1},
				{1,2,2,2,2,1,1,1,1},
				{1,2,1,2,1,0,0,0,0},
				{1,1,2,1,1,0,0,0,0}};
		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(), maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		
		Pacman pacman = new Pacman();
		pacman.setLocation(new Location(60, 60));
		Ghost ghost = new Ghost(new Location(20, 20), 90, "Jos");
		Explorer explorer = new Explorer(ghost.getMaze());
		ghost.setStrategy(explorer);
		
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		
		Communicator communicator = new Communicator();		
		ghost.setCommunicator(communicator);
		
		simulator.addGhost(ghost, new Location(20, 20), 90);
		simulator.setPacman(pacman);
		
		GuiTest Gui = new GuiTest(simulator, null);
		
		ghost.run();
	}

	private static void testGui() throws IOException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,2,1,2,2,1,2,2,1,2,1,2,1,2,2,1,2,2,2,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,2,2,2,1,1,2,1,1,2,2,1,2,2,2,1,2,1,2,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1,1,2,1,2,1,2,1,2,1,1,2,1,1,1,2,1,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,2,1,2,1,2,1,2,1,2,2,1,1,2,1,2,1,1,2,1},
				{1,2,1,2,2,1,2,1,2,1,2,1,1,1,2,1,1,2,1,2,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,1},
				{1,2,1,2,2,2,1,2,2,1,2,1,2,1,2,1,2,1,2,1,2,2,1,2,2,1,2,1,2,1,2,1,2,2,1,1,2,1,2,2,1},
				{1,2,1,2,1,2,1,2,1,2,2,1,2,1,2,1,2,1,2,2,1,2,1,2,1,2,2,1,2,1,2,2,1,2,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,1,2,1,2,1,1,2,1,2,1,2,2,1,2,1,2,1,2,1,2,1,2,1,2,2,2,1,2,1,2,2,2,2,2,1},
				{1,2,1,2,2,2,1,2,1,1,2,1,2,1,2,1,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1},
				{1,2,1,2,1,2,1,2,2,1,2,1,2,1,2,1,2,1,2,1,1,2,1,2,1,2,1,2,1,1,2,1,2,2,1,2,1,2,1,2,1},
				{1,1,2,1,1,1,2,1,1,2,2,1,2,1,2,1,2,1,2,1,2,1,1,2,1,2,2,1,1,1,2,2,1,2,1,2,1,2,1,2,1},
				{1,2,1,2,2,1,2,2,1,2,2,1,2,1,2,1,2,1,2,2,2,1,1,2,1,1,2,1,2,2,2,1,1,2,1,2,1,2,1,2,1},
				{1,1,2,1,1,2,2,1,1,2,2,1,2,1,2,1,2,1,2,1,1,1,2,2,2,1,2,2,1,2,1,2,1,2,1,1,2,1,1,2,1},
				{1,2,2,1,2,2,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,1,2,1,2,1,2,1,1,2,1,2,2,2,1,1},
				{1,2,2,2,1,2,1,1,2,1,2,2,1,2,2,1,2,1,2,2,2,1,2,1,2,1,2,1,1,2,1,2,2,1,2,1,2,1,1,2,1},
				{1,1,1,2,1,1,2,1,2,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,2,2,1,1,2,1,2,1,1,2,1,2,1,2,2,1},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{1,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,1,1,2,1,1}};
		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, 20, 20);
		Simulator simulator = new Simulator(maze, colorMap);
		
		Pacman pacman = new Pacman();
		Ghost ghost1 = new Ghost(new Location(60,20), 0, "Jos");
		Ghost ghost2 = new Ghost(new Location(400,400), 0,"Jef");
		Ghost ghost3 = new Ghost(new Location(400,200), 0,"Jan");
		Ghost ghost4 = new Ghost(new Location(200,400), 0,"Joe");
				
		simulator.setPacman(pacman);
		simulator.addGhost(ghost1, ghost1.getLocation(), ghost1.getRotation());
		simulator.addGhost(ghost2, ghost1.getLocation(), ghost1.getRotation());
		simulator.addGhost(ghost3, ghost1.getLocation(), ghost1.getRotation());
		simulator.addGhost(ghost4, ghost1.getLocation(), ghost1.getRotation());
		
		//GuiTest gui = new GuiTest(simulator, maze, colorMap);
	}

	private static void testCommunicator()
	{
		Communicator comm = new Communicator();
		comm.travel(20);
		System.out.println(comm.getDistance());
	}
	
	private static void testGhost() throws IOException{
		ColorMap colorMap = new ColorMap();
		Maze maze= new Maze(100);
		Simulator simulator = new Simulator(maze, colorMap);
		Ghost ghost = new Ghost(new Location(0,0), 0, "Jan");
		simulator.addGhost(ghost, new Location(0,0), 0);
		ghost.run();
	}
	
	private static void testMaze()
	{
		/**
		 * Test Maze:
		 * 
		 *  _ _ _
		 * |  _  |
		 * | |_| |
		 * |_ _ _|
		 * 
		 * 2121212
		 * 1221221
		 * 1211121
		 * 1121211
		 * 
		 */
		/**char mazedata[4][7] = {
				{2,1,2,1,2,1,2},
				{1,2,2,1,2,2,1},
				{1,2,1,1,1,2,1},
				{1,1,2,1,2,1,1}
		}
		Maze maze = new Maze(mazedata);	
		
		Ghost ghost = new Ghost(new Location(0.0,0.0), maze);
		
		System.out.println("Start locatie");
		System.out.println(ghost.getLocation());
		System.out.println("Start rotatie");
		System.out.println(ghost.getRotation());
		System.out.println("Ultrasonic:");
		System.out.println(ghost.getUltrasonicSensor().getDistance());
		
		
		Simulator simulator = new Simulator();
		Pacman pacman = new Pacman(new Location(40,0), simulator);
		simulator.addGhost(ghost);
		simulator.setPacman(pacman);
		System.out.println("InfraRed:");
		System.out.println(ghost.getInfraredSensor().getDirection());
		
		ghost.rotate(90);
		System.out.println("InfraRed:");
		System.out.println(ghost.getInfraredSensor().getDirection());
		
		ghost.rotate(-45);
		System.out.println("InfraRed:");
		System.out.println(ghost.getInfraredSensor().getDirection());
		
		ghost.rotate(135);
		System.out.println("InfraRed:");
		System.out.println(ghost.getInfraredSensor().getDirection()); **/
	}
	
	private static void testColorMap()
	{
		ColorMap colorMap = new ColorMap();
		
		//colorMap.testReadImage();
		//colorMap.testAddBarcode();		
		colorMap.setupMap();
		colorMap.distortion = 10;
		//colorMap.testGetSensorReading();
		colorMap.TestReadValueOverlap();
		
	}
	
	private static void testBarcodeAnalyser()
	{
		BarcodeAnalyser analyser = new BarcodeAnalyser();
		
		//analyser.TestGetLastPossibleReading();
		//analyser.TestCalculateBarcode();
		analyser.TestUpdate();
	}
	
	private static void testRidingBarcodeAnalyser() throws IOException
	{
		/**
		 * Test Maze:
		 * 
		 *  _ _ _
		 * |  _  |
		 * |b|_| |
		 * |_ _ _|
		 * 
		 * 2121212
		 * 1221221
		 * 1211121
		 * 1121211
		 * (b = barcode 01011010, -y to y)
		 */
		char mazedata[][] = {
				{2,1,2,1,2,1,2},
				{1,2,2,1,2,2,1},
				{1,2,1,1,1,2,1},
				{1,1,2,1,2,1,1}
		};
		
		Maze maze = new Maze(mazedata);
		ColorMap colormap = new ColorMap();
		colormap.setupMap(maze, 3, 3);
		colormap.AddBarcode(0, 1, "01101010", 1);
		colormap.AddBarcode(0, 0, "01101010", 1);
		
		//colormap.showImage(colormap.tileMap[0][0]);
		colormap.showImage(colormap.tileMap[0][1]);
		//colormap.showImage(colormap.tileMap[0][2]);
		
		Ghost ghost = new Ghost(new Location(20,1), 90, "jos");
		ghost.barcodeAnalyser.SetBrownValue(128);
		
		Simulator simulator = new Simulator(maze, colormap);
		simulator.addGhost(ghost, new Location(20,1), 90);
		//simulator.setPacman(new Pacman(simulator));
		
				
		//simulator.getGhostLocations().put(ghost, new Location(20, 14.6));		
		//System.out.println(ghost.getLightSensor().readValue());
		
		System.out.println("Started");
		ghost.run();
		ghost.travel(99, false, false);
				
		
		
		int prevReading = 0;
		Location ghostLoc = simulator.getGhostLocations().get(ghost);
		
		while(ghostLoc.y<=85)
		{
			ghostLoc = simulator.getGhostLocations().get(ghost);
			System.out.println(ghostLoc.y);
			
			
			int cReading = ghost.getLightSensor().readValue();
			if(prevReading != cReading)
			{
				prevReading = cReading;
				//System.out.println(cReading+ " Pos: "+ghostLoc.x+" "+ghostLoc.y);
			}
			
		}
		System.out.println("Finished Run");
		ghost.terminated = true;
		System.out.println("Expected barcode: 01010110 (2 times)");
		
		/*
		String output = "";
		for(int i=0; i<ghost.barcodeAnalyser.readings.size(); i++)
		{
			output+=ghost.barcodeAnalyser.readings.get(i);
			output+=" ";			
		}
		System.out.println(output);*/
		
		
		
	}
	
	private static void sleep(int milli)
	{
		try {
			Thread.sleep(milli);
		} catch (InterruptedException e) {
		}
	}
	private static void testMazeCorrector() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
		pacman.setLocation(new Location(140,140));
		simulator.setPacman(pacman);
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(1, 3, "01000110", 0);
		simulator.getMaze().addBarcode(5, 2, "01110110", 0);
		simulator.getMaze().addBarcode(0, 2, "01011100", 1);
		
	    Game game = new Game();
		Channel channel = game.getChannel();
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos");
		Ghost ghost1 = new Ghost(new Location(20,20), 0, "Jef");
		Ghost ghost2 = new Ghost(new Location(20,20), 0, "Jan");
		Ghost ghost3 = new Ghost(new Location(20,20), 0, "Jeroen");
//		ghost.getMaze().addBarcode(3, 0, "01010110", 0);
//		ghost3.getMaze().addBarcode(0, 0, "01010110", 0);
		Ghost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.setGhosts(ghosts);
		ghost.setStrategy (new MazeCorrector(ghost.getMaze()));
		ghost1.setStrategy (new MazeCorrector(ghost1.getMaze()));
		ghost2.setStrategy(new MazeCorrector(ghost2.getMaze()));
		ghost3.setStrategy(new MazeCorrector(ghost3.getMaze()));
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		
		simulator.addGhost(ghost, new Location(140, 140), 0);
		simulator.addGhost(ghost1, new Location(60, 60), 0);
		simulator.addGhost(ghost2, new Location(100, 60), 0);
		simulator.addGhost(ghost3, new Location(20, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.speed = 700;
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		//t1.start();
		//t2.start();
		//t3.start();
		t4.start();
	}

	private static void testBarcodeReal() throws IOException
	{
		Ghost ghost = new Ghost(new Location(0,0), 0, "Jef");
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		ghost.setCommunicator(new Communicator());
		
		char mazedata[][] = {
				{2,1,2,1,2,1,2},
				{1,2,2,1,2,2,1},
				{1,2,1,1,1,2,1},
				{1,1,2,1,2,1,1}
		};
		Maze maze = new Maze(mazedata);	
		ColorMap colormap = new ColorMap();
		colormap.setupMap(maze, 3, 3);
		Simulator sim = new Simulator(maze, colormap);
		ghost.setSimulator(sim);
		
		ghost.run();
		
		ghost.travel(40, false, false);
		//Wanneer de robot over een gekende en herkende barcode rijdt, output hij deze barcode
		//(ge moet de barcode dus wel nog toevoegen in de barcodeanalyser)
		
		while(true)
		{
			System.out.println(ghost.getLightSensor().readValue());
		}
	}

	private static void testExplorer() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		 Game game = new Game();
		Pacman pacman = game.getPacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,2));
		simulator.setPacman(pacman);

		simulator.setPacmanLocation(new Location(60, 180));

		

		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);		
		
	   
		VirtualGhost ghost = new VirtualGhost(game,"Jos", simulator);
		VirtualGhost ghost1 = new VirtualGhost(game,"Jef", simulator);
		VirtualGhost ghost2 = new VirtualGhost(game,"Jan", simulator);
		VirtualGhost ghost3 = new VirtualGhost(game,"Joost", simulator);
		ghost.setSpeed(800);


		OwnGhost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.addFourOwnGhost(ghosts);

		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		simulator.addGhost(ghost1, new Location(140, 60), 0);
		simulator.addGhost(ghost2, new Location(100, 60), 0);
		simulator.addGhost(ghost3, new Location(20, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		//simulator.getMaze().draw(-1, -1);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
		t2.start();
		t3.start();
		t4.start();

		MainGui mainGui = new MainGui(game, simulator.getMaze(), simulator);


		
	}
	private static void testExplorerOneGhost() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,4));

		simulator.setPacman(pacman);
		simulator.setPacmanLocation(new Location(60, 180));
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);		
	    Game game = new Game();
//	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());
		VirtualGhost ghost = new VirtualGhost(game,"Jos", simulator);
//		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.setSpeed(600);

		game.addOwnGhost(ghost);
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
		//GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();
		//while(!game.readySetGo());
		//GhostPanel panel1 = new GhostPanel(ghost, game);
		MainGui mainGui = new MainGui(game, maze, simulator);
		
	}
	private static void testExplorerOneGhostVirtualSensorInnaccurate() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,4));

		simulator.setPacman(pacman);
		simulator.setPacmanLocation(new Location(60, 180));
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);		
		
	    Game game = new Game();
//	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());
		VirtualGhost ghost = new VirtualGhost(game,"Jos", simulator,true);
//		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.setSpeed(900);

		game.addOwnGhost(ghost);
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
		//GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		t1.start();
		//while(!game.readySetGo());
		//GhostPanel panel1 = new GhostPanel(ghost, game);
		MainGui mainGui = new MainGui(game, maze, simulator);
		
	}
	private static void testExplorerVirtualSensorsInaccurate() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException
	{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
		

		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(1,4));

		simulator.setPacman(pacman);
		simulator.setPacmanLocation(new Location(60, 180));
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(5, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(new Coordinate(1, 3), "01000110", 0);
		simulator.getMaze().addBarcode(new Coordinate(5, 2), "01110110", 0);
		simulator.getMaze().addBarcode(new Coordinate(0, 2), "01011100", 1);		
		
	    Game game = new Game();
//	    RealGhost ghost= new RealGhost(game, "Jos", simulator, new Communicator());
		VirtualGhost ghost = new VirtualGhost(game,new Location(20,20),"Jos", simulator,true);
		VirtualGhost ghost1 = new VirtualGhost(game,new Location(20,20),"Jef", simulator,true);
		VirtualGhost ghost2 = new VirtualGhost(game,new Location(20,20),"Jan", simulator,true);
		VirtualGhost ghost3 = new VirtualGhost(game,new Location(20,20),"Joost", simulator,true);
//		((SectorAnalyserV1)(ghost.sectorAnalyser)).frontCompensation=3;
		ghost.setSpeed(800);
		ghost1.setSpeed(800);
		ghost2.setSpeed(800);
		ghost3.setSpeed(800);



		OwnGhost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.addFourOwnGhost(ghosts);
//		game.addOwnGhost(ghost);

		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		simulator.addGhost(ghost1, new Location(60, 60), 0);
		simulator.addGhost(ghost2, new Location(100, 60), 0);
		simulator.addGhost(ghost3, new Location(20, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.getMaze().draw(-1, -1);
		//GuiTest Gui = new GuiTest(simulator, game);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
		t2.start();
		t3.start();
		t4.start();
		MainGui mainGui = new MainGui(game, maze, simulator);
//		while(!game.readySetGo());
//		GhostPanel panel1 = new GhostPanel(ghost, game);
//		GhostPanel panel2 = new GhostPanel(ghost1, game);
//		GhostPanel panel3 = new GhostPanel(ghost2, game);
//		GhostPanel panel4 = new GhostPanel(ghost3, game);

		
	}
	public static void testFourSimulators() throws IOException, InterruptedException{
		File file = new File("../wolfraam.txt");
		
		int numberOfPlayers = 4;
		
		Pacman pacman = new Pacman();
		
		Game []games = new Game[numberOfPlayers];
		
		Simulator[] simulators = new Simulator[numberOfPlayers];
		
		Location[] robotLocations = {new Location(20,220),
									new Location(20,20),
									new Location(300,20),
									new Location(300, 220)};
		
		VirtualGhost [] ghosts = new VirtualGhost[numberOfPlayers];
		String [] ghostNames = {"ghost1", "ghost2", "ghost3", "ghost4"};
		
		Thread [] ghostThreads = new Thread[numberOfPlayers];
		Maze parsedMaze = null;
		for(int i = 0; i < numberOfPlayers; i++){
			games[i] = new Game(numberOfPlayers);
			CommandParser parser = new CommandParser(games[i]);
			GameInformation info = parser.parseFile(file);
			parsedMaze = info.maze;
			ColorMap colorMap = new ColorMap();
			colorMap.setupMap(parsedMaze, parsedMaze.getSize(),parsedMaze.getSize());
			simulators[i] = new Simulator(parsedMaze, colorMap);
			pacman.setCoordinate(games[i].getPacman().getCoordinate());
			simulators[i].setPacman(pacman);
			simulators[i].setMaze(parsedMaze);
			ghosts[i] = new VirtualGhost(games[i], ghostNames[i], simulators[i]);
			games[i].addOwnGhost(ghosts[i]);
			simulators[i].addGhost(ghosts[i], robotLocations[i], 0);
			
			ghostThreads[i] = new Thread(new GhostRunner(ghosts[i]));
			ghostThreads[i].start();
			Thread.sleep(500);
		}	
		MainGui gui = new MainGui(games[0], parsedMaze, simulators[0]);
			
//		while(!games[0].readySetGo() && !games[1].readySetGo() && !games[2].readySetGo() && !games[3].readySetGo());
		/*System.out.println("start");
		
		System.out.println("XXXXXXXXXX");
		System.out.println("STOP THREAD van 1Ghost1 binnen 1 sec");
		System.out.println("XXXXXXXXXX");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		ghostThreads[0].stop();
		
		System.out.println("XXXXXXXXXX");
		System.out.println("Thread Jos gestopt, 2 sec wachten en dan nieuwe ghost aanmaken");
		System.out.println("XXXXXXXXXX");
		
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		Game crashGame = new Game();
		CommandParser parser = new CommandParser(crashGame);
		Maze parsedMazeCrash = parser.parseFile(file);
		ColorMap colorMapCrash = new ColorMap();
		colorMapCrash.setupMap(parsedMazeCrash, parsedMazeCrash.getSize(),parsedMazeCrash.getSize());
		Simulator crashSim = new Simulator(parsedMazeCrash, colorMapCrash);
		crashSim.setPacman(pacman);
		VirtualGhost crashGhost = new VirtualGhost(crashGame, "crashed1", crashSim);
		crashGame.addOwnGhost(crashGhost);
		crashSim.addGhost(crashGhost, robotLocations[0], 0);
		
		System.out.println("XXXXXXXXXX");
		System.out.println("Start crashedGhost " + ghostNames[0]);
		System.out.println("XXXXXXXXXX");
		
		Thread crashedGhost = new Thread(new GhostRunner(crashGhost));
		crashedGhost.start();
		*/
	}
	
	public static void testOneOfFour() throws IOException{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}, 
				{1,1,2,1,2,1,2,2,2,2,1,2,1,2,2,1,2,1,2,1,2,1,1},
				{1,2,2,1,2,1,2,1,1,1,2,1,2,2,1,1,2,1,2,1,2,1,1},
				{1,2,1,2,1,1,2,2,2,1,2,1,2,2,2,1,2,2,2,1,2,2,1},
				{1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,1,1,2,1,2,1,1,1},
				{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};		
		//Maze maze = new Maze(walls);
		Game game = new Game(2);
		CommandParser parser = new CommandParser(game);
		GameInformation info = parser.parseFile(new File("../wolfraam.txt"));
		Maze maze = info.maze;
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		
		Pacman pacman = new Pacman();
		pacman.setCoordinate(new Coordinate(3,3));
		
		int numberOfPlayers = 4 ;
		//uniek PER PC
//		int playerNumber = 0;
		int playerNumber = 0;
		
		Simulator simulator = new Simulator(maze, colorMap);
		
		Coordinate[] robotLocations = info.playerCoordinates;
		String [] ghostNames = {"Jos", "Jef", "Jan", "Jeroen"};
		
		Thread ghostThread;
		
		simulator.setPacman(pacman);
		
		VirtualGhost ghost = new VirtualGhost(game, new Location(20,20), ghostNames[playerNumber], simulator);
//		VirtualGhost ghost = new VirtualGhost(game, new Location(20,20), "CrashedGhost", simulator);
		game.addOwnGhost(ghost);
		
		simulator.addGhost(ghost, Coordinate.toLocation(robotLocations[playerNumber]), 0);
		ghostThread = new Thread(new GhostRunner(ghost));
		sleep(100);
		
		ghostThread.start();
	}
	
	public static void realandSimulation(String args[]) throws IOException{
		char[][] walls = { //index with maze[-y][x]
				{0,1,0,1,0,1,0,1,0},
					{1,2,2,1,2,1,2,2,1},
					{1,1,1,1,2,1,2,2,1},
					{1,2,2,1,2,1,2,2,1},
					{1,1,2,1,2,1,1,1,1}};
		

		Communicator communicator = new Communicator();		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setLocation(new Location(100,60));

		simulator.setPacman(pacman);
		colorMap.AddBarcode(1, 3, "01000110", 0);
		colorMap.AddBarcode(2, 2, "01110110", 0);
		colorMap.AddBarcode(0, 2, "01011100", 1);
		
		simulator.getMaze().addBarcode(1, 3, "01000110", 0);
		simulator.getMaze().addBarcode(2, 2, "01110110", 0);
		simulator.getMaze().addBarcode(0, 2, "01011100", 1);
		
	    Game game = new Game();
		Ghost ghost = new Ghost(new Location(20,20), 0, "Jos",game);
		Ghost ghost1 = new Ghost(new Location(20,20), 0, "Jef",game);
		Ghost ghost2 = new Ghost(new Location(20,20), 0, "Jan",game);
		Ghost ghost3 = new Ghost(new Location(20,20), 0, "Jeroen",game);
		
		ghost.setCommunicator(communicator);
		ghost.setUltrasonicSensor(new RealUltrasonicSensor(ghost));
		ghost.setLightSensor(new RealLightSensor(ghost));
		ghost.setInfraredSensor(new RealInfraredSensor(ghost));
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost.xOffsetSensor=-4;
		ghost.yOffsetSensor=2;
		ghost.frontCompensation=4;
		//ghost.getMaze().addBarcode(3, 0, "01010110", 0);
		//ghost3.getMaze().addBarcode(0, 0, "01010110", 0);
		Ghost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.setGhosts(ghosts);
		ghost.setStrategy(new Explorer(ghost.getMaze()));
		ghost1.setStrategy(new Explorer(ghost1.getMaze()));
		ghost2.setStrategy(new Explorer(ghost2.getMaze()));
		ghost3.setStrategy(new Explorer(ghost3.getMaze()));
//		ghost.secondaryStrategy = new PacmanFinder(ghost.getMaze());
//		ghost1.secondaryStrategy = new PacmanFinder(ghost1.getMaze());
//		ghost2.secondaryStrategy = new PacmanFinder(ghost2.getMaze());
//		ghost3.secondaryStrategy = new PacmanFinder(ghost3.getMaze());
		//Explorer02 explorer = new Explorer02(ghost.getMaze());
		//explorer.sim = simulator;
		//explorer.g = ghost;
		//ghost.strategy = explorer;
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
		simulator.addGhost(ghost1, new Location(60, 60), 0);
		simulator.addGhost(ghost2, new Location(100, 140), 0);
		simulator.addGhost(ghost3, new Location(20, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		simulator.speed = 800;
		simulator.getMaze().draw(-1, -1);
		GuiTest Gui = new GuiTest(simulator, game);
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
		t2.start();
		t3.start();
		t4.start();
	}
	
	public static void testBarcodesVirtual() throws IOException{
		char[][] walls = { //index with maze[-y][x]
				{2,1,2}, 
				{1,2,1},
				{1,2,1,},
				{1,2,1,},
				{1,2,1,},
				{1,1,1,},
				};
		
		
		
		Maze maze = new Maze(walls);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		 Game game = new Game();
		Pacman pacman = game.getPacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setCoordinate(new Coordinate(0,3));

		simulator.setPacman(pacman);
		//simulator.setPacmanLocation(new Location(20, 195));
		colorMap.AddBarcode(0, 1, "01000110", 1);
		
		
		simulator.getMaze().addBarcode(new Coordinate(0, 1), "01000110", 1);
		
		
	   
		VirtualGhost ghost = new VirtualGhost(game,"Jos", simulator);
		VirtualGhost ghost1 = new VirtualGhost(game,"Jef", simulator);
		VirtualGhost ghost2 = new VirtualGhost(game,"Jan", simulator);
		VirtualGhost ghost3 = new VirtualGhost(game,"Joost", simulator);
		ghost.setSpeed(800);
		ghost1.setSpeed(800);
		ghost2.setSpeed(800);
		ghost3.setSpeed(800);


		OwnGhost[] ghosts = {ghost, ghost1, ghost2, ghost3};
		game.addFourOwnGhost(ghosts);
		
		
		simulator.addGhost(ghost, new Location(20, 20), 0);
//		simulator.addGhost(ghost1, new Location(60, 60), 0);
//		simulator.addGhost(ghost2, new Location(100, 60), 0);
//		simulator.addGhost(ghost3, new Location(20, 140), 0);
		// speed ook readsize barcode nodig om aan te passen.
		//simulator.getMaze().draw(-1, -1);
		
		
		Thread t1 = new Thread(new GhostRunner(ghost));
		Thread t2 = new Thread(new GhostRunner(ghost1));
		Thread t3= new Thread(new GhostRunner(ghost2));
		Thread t4 = new Thread(new GhostRunner(ghost3));
		t1.start();
//		t2.start();
//		t3.start();
//		t4.start();
		while(!game.readySetGo());

		
		MainGui mainGui = new MainGui(game, simulator.getMaze(), simulator);

	}
	
	public static void runVirtual() throws IOException{
		
		char[][] walls = { //index with maze[-y][x]
				{0,1,0,1,0,1,0,1,0},
					{1,2,2,1,2,1,2,2,1},
					{1,1,1,1,2,1,2,2,1},
					{1,2,2,1,2,1,2,2,1},
					{1,1,2,1,2,1,1,1,1}};
		

		Communicator communicator = new Communicator();		
		Maze maze = new Maze(walls);
		maze.addBarcode(new Coordinate(1, 3), "01000110", 0);
		maze.addBarcode(new Coordinate(2, 2), "01110110", 0);
		maze.addBarcode(new Coordinate(0, 2), "01000110", 1);
		ColorMap colorMap = new ColorMap();
		colorMap.setupMap(maze, maze.getSize(),maze.getSize());
		Simulator simulator = new Simulator(maze, colorMap);
		Simulator simulator2 = new Simulator(maze, colorMap);
		Simulator simulator3 = new Simulator(maze, colorMap);
		Simulator simulator4 = new Simulator(maze, colorMap);
		Pacman pacman = new Pacman();
//		pacman.setLocation(new Location(180,180));
		pacman.setLocation(new Location(100,60));
		simulator.setPacman(pacman);
		simulator2.setPacman(pacman);
		simulator3.setPacman(pacman);
		simulator4.setPacman(pacman);
		Game g1 = new Game();
		OwnGhost ghost = new VirtualGhost(g1,"Jos", simulator);
		simulator.addGhost(ghost, new Location(20, 20), 0);
		g1.addGhost(ghost);
		
	}
	
}
